package guda.house.dal.dao.impl;

import guda.grape.autogen.common.BaseDAO;
import guda.house.dal.dao.BillWaterDAO;
import guda.house.dal.dataobject.BillWaterDO;
import guda.grape.autogen.common.page.BaseQuery;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BillWaterDAOImpl extends BaseDAO implements BillWaterDAO {

    @Override
	public Long insert(BillWaterDO billWater) {
	      try {
                return (Long) getSqlMapperW().insert("bill_water.insert",billWater);
          } catch (Exception e) {
                throw new RuntimeException(e);
          }

	}

    @Override
	public BillWaterDO getBillWaterById(Long recordId) {
	    return (BillWaterDO)getSqlMapClientTemplate().queryForObject("bill_water.getBillWaterById", recordId);
	}

    @Override
	public boolean delBillWaterById(Long recordId) {
	    int num = 0;
        try {
            num = getSqlMapperW().delete("bill_water.delBillWaterById",recordId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        if(num>0){
            return true;
        }else{
            return false;
        }
	}

    @Override
	public List<BillWaterDO> getBillWaterByIds(List idsList) {
        Map m = new HashMap();
        m.put("idsList",idsList);
		return getSqlMapClientTemplate().queryForList("bill_water.selectByIds", m);
	}

    @Override
	public void cleanAutoIncrement(Long recordId) {
	    try {
            getSqlMapperW().update("bill_water.cleanAutoIncrement",recordId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
	}

    @Override
    public List<BillWaterDO> selectForPage(BaseQuery baseQuery) {
        return getSqlMapClientTemplate().queryForList("bill_water.selectForPage", baseQuery);
    }

    @Override
    public int countForPage(BaseQuery baseQuery) {
        return (Integer)getSqlMapClientTemplate().queryForObject("bill_water.countForPage",baseQuery);
    }

    @Override
    public void updateByIdSelective(BillWaterDO billWater) {
        try {
            getSqlMapperW().update("bill_water.updateByIdSelective",billWater);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public List<BillWaterDO> getBill(Long suiteId, Integer recordYear, Integer recordMonth) {
        Map m = new HashMap();
        m.put("suiteId",suiteId);
        m.put("recordYear",recordYear);
        m.put("recordMonth",recordMonth);
        return getSqlMapClientTemplate().queryForList("bill_water.getBill", m);
    }

    @Override
    public List<BillWaterDO> selectForUnpay(BaseQuery baseQuery) {
        return getSqlMapClientTemplate().queryForList("bill_water.selectForUnpay", baseQuery);
    }

    @Override
    public int countForUnpay(BaseQuery baseQuery) {
        return (Integer)getSqlMapClientTemplate().queryForObject("bill_water.countForUnpay",baseQuery);
    }

    @Override
    public Long statBill(List<Long> suiteIdList, String gmtDate, Integer isPayed) {
        Map m = new HashMap();
        m.put("suiteIdList",suiteIdList);
        m.put("gmtDate",gmtDate);
        m.put("isPayed",isPayed);
        return (Long)getSqlMapClientTemplate().queryForObject("bill_water.statBill", m);
    }

    @Override
    public Long statBillRate(List<Long> suiteIdList, String gmtStart, String gmtEnd, Integer isPayed) {
        Map m = new HashMap();
        m.put("suiteIdList",suiteIdList);
        m.put("gmtStart",gmtStart);
        m.put("gmtEnd",gmtEnd);
        m.put("isPayed",isPayed);
        return (Long)getSqlMapClientTemplate().queryForObject("bill_water.statBillRate", m);
    }

    @Override
    public List<BillWaterDO> getByPayId(long payId) {
        return getSqlMapClientTemplate().queryForList("bill_water.getByPayId", payId);
    }

    @Override
    public BillWaterDO queryLatest(Long suiteId) {
        return (BillWaterDO)getSqlMapClientTemplate().queryForObject("bill_water.queryLatest",suiteId);
    }

    @Override
    public Long statDichanDiscount(List<Long> suiteIdList, String gmtDate) {
        Map m = new HashMap();
        m.put("suiteIdList",suiteIdList);
        m.put("gmtDate",gmtDate);
        return (Long)getSqlMapClientTemplate().queryForObject("bill_water.statDichanDiscount", m);
    }

    @Override
    public Long statSelfDiscount(List<Long> suiteIdList, String gmtDate) {
        Map m = new HashMap();
        m.put("suiteIdList",suiteIdList);
        m.put("gmtDate",gmtDate);
        return (Long)getSqlMapClientTemplate().queryForObject("bill_water.statSelfDiscount", m);
    }

    @Override
    public List<BillWaterDO> statLastBill(List<Long> suiteIdList, Integer isPayed) {
        Map m = new HashMap();
        m.put("suiteIdList",suiteIdList);
        m.put("isPayed",isPayed);
        return getSqlMapClientTemplate().queryForList("bill_water.statLastBill", m);
    }

    @Override
    public List<BillWaterDO> getBillList(List<Long> suiteIdList, Date gmtStart, Date gmtEnd, Integer isPayed) {
        Map m = new HashMap();
        m.put("suiteIdList",suiteIdList);
        m.put("startDate",gmtStart);
        m.put("endDate",gmtEnd);
        m.put("isPayed",isPayed);
        return getSqlMapClientTemplate().queryForList("bill_water.getBillList", m);
    }

    @Override
    public List<BillWaterDO> getBillByYear(List<Long> suiteIdList, Integer recordYear, Integer isPayed) {
        Map m = new HashMap();
        m.put("suiteIdList",suiteIdList);
        m.put("recordYear",recordYear);
        m.put("isPayed",isPayed);
        return getSqlMapClientTemplate().queryForList("bill_water.getBillByYear", m);
    }

    @Override
    public Long statBillByYear(List<Long> suiteIdList, Integer year, Integer isPayed) {
        Map m = new HashMap();
        m.put("suiteIdList",suiteIdList);
        m.put("recordYear",year);
        m.put("isPayed",isPayed);
        return (Long)getSqlMapClientTemplate().queryForObject("bill_water.statBillByYear", m);
    }

    @Override
    public Long statPaidBill(List<Long> billIdList) {
        Map m = new HashMap();
        m.put("billIdList",billIdList);
        return (Long)getSqlMapClientTemplate().queryForObject("bill_water.statPaidBill", m);
    }

}

